﻿using System.Collections.Generic;
using System.Xml.Linq;
using NFLManager.Properties;

namespace NFLManager
{
    class NflDictionary
    {

        #region fields

        protected static NflDictionary _nflDict = null;

        private readonly Dictionary<string, string> _teamIdtoDesc = new Dictionary<string, string>();
        private readonly Dictionary<string, string> _teamIdtoDiv = new Dictionary<string, string>();
        private readonly Dictionary<string, string> _teamIdtoConf = new Dictionary<string, string>();

        #endregion
        
        protected NflDictionary()
        {
            var nodes = XDocument.Load(@"..\..\..\" + Settings.Default.DATA_PATH + @"NFL_DICT.xml").Descendants("elem");
            foreach (var node in nodes)
            {
                _teamIdtoDesc.Add(
                    (((string)node.Element("id")).Replace("\r\n", "")).Trim(),
                    (((string)node.Element("description")).Replace("\r\n", "")).Trim());
                _teamIdtoDiv.Add(
                    (((string)node.Element("id")).Replace("\r\n", "")).Trim(),
                    (((string)node.Element("division")).Replace("\r\n", "")).Trim());
                _teamIdtoConf.Add(
                    (((string)node.Element("id")).Replace("\r\n", "")).Trim(),
                    (((string)node.Element("conference")).Replace("\r\n", "")).Trim());
            }
        }
        
        #region properties
        
        public Dictionary<string, string> TeamIdtoDesc
        {
            get { return _teamIdtoDesc; }
        }

        public Dictionary<string, string> TeamIdtoDiv
        {
            get { return _teamIdtoDiv; }
        }

        public Dictionary<string, string> TeamIdtoConf
        {
            get { return _teamIdtoConf; }
        }

        public static NflDictionary Istance
        {
            get { return _nflDict ?? (_nflDict = new NflDictionary()); }
        }

        #endregion
        
    }
}
